﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HCM_maps_website.Process.BLL;
using HCM_maps_website.Models;

namespace HCM_maps_website.Controllers
{
    public class MobileController : Controller
    {
        //
        // GET: /Mobile/

        public ActionResult Index()
        {
            return View();
        }

        public PartialViewResult Search(string keywords)
        {

            List<int> arrpos = new List<int>();

            for (int i = 1; i < keywords.Length - 1; i++)
            {
                if (keywords[i] == '.' && (keywords[i - 1].ToString().ToLower() == "q" ||
                    (keywords[i - 1].ToString().ToLower() == "p" && (i < 2 || (i >= 2 && keywords[i - 2].ToString().ToLower() != "t")))))
                {
                    arrpos.Add(i);
                }
            }

            for (int i = arrpos.Count - 1; i >= 0; i--)
            {
                keywords = keywords.Remove(arrpos[i], 1);
            }

            SearchResult lstresult = SearchBLL.Search(keywords);

            return PartialView("_InfoMobile", new Tuple<IEnumerable<ServiceModel>, IEnumerable<PlaceModels>>(lstresult.Service, lstresult.Place));
        }
    }
}
